@extends('admin.frame_layout')
<?php $top_selected = "工作台";$page_menu = "未发货订单" ?>

@section('content')
    <div class="formbody">
        <div class="formtitle"><span>发货信息预览编辑</span></div>

        <table class="tablelist">
            <thead>
            <tr>
                <th width="100">订单编号<i class="sort"><img src="{{asset('admin/imgs/px.gif')}}"/></i></th>
                <th>会员账号</th>
                {{--<th>购买的商品</th>--}}
                {{--<th>商品数量</th>--}}
                <th>商品购买信息</th>
                <th>订单金额</th>
                <th>收货地址</th>
                <th>联系方式</th>
                <th>订单备注</th>
                <th width="160px">下单时间</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>{{(isset($order)?($order->no):0)}}</td>
                <td>{{(isset($order)?($order->user->username):0)}}</td>
                {{--<td>--}}
                {{--<a href="{{route('admin.product',['pro'=>$order->id])}}">--}}
                {{--{{$good->title}}--}}
                {{--</a>--}}
                {{--</td>--}}
                <td>{!! (isset($order)?($order->good_info):0) !!}</td>
                <td class="red">{{(isset($order)?($order->price):0)}}</td>
                <td>
                    {{\App\Models\MArea::find($order->province)['name']}}
                    {{\App\Models\MArea::find($order->city)['name']}}
                    {{\App\Models\MArea::find($order->county)['name']}}
                    {{(isset($order)?($order->addr):0)}}
                </td>
                <td>{{(isset($order)?($order->tel):0)}}</td>
                <td>{{(isset($order)?($order->detail==''?'无':$order->detail):0)}}</td>
                <td>{{date("Y-m-d H:i:s",(isset($order)?($order->create_time):0))}}</td>
            </tr>
            </tbody>
        </table>

        <form action="{{route('admin.order.ship',['id'=>(isset($order)?($order->id):0)])}}" method="post"
              id="admin" style="margin-top: 50px;">
            {!! csrf_field() !!}
            <ul class="forminfo">

                <li>
                    <label class="lable">收货地址</label>
                    <select name="province" id="province" style="width: 130px;">
                        <option value="">==省==</option>
                        @foreach($provinces as $province)

                            <option value="{{$province ->id}}"

                                    @if($order && $order->province == $province ->id)
                                    selected
                                    @endif>
                                {{$province->name}}
                            </option>
                        @endforeach
                    </select>
                    <select name="city" id="city" style="width: 130px;">
                        @if($order && $order->city)
                            @foreach($citys as $city)
                                <option value="{{$city->id}}"
                                        @if($order && $order->city == $city->id)
                                        selected
                                        @endif>
                                    {{$city->name}}
                                </option>
                            @endforeach
                            {{--<option value="{{$order->city}}">{{getAreaById($order->city)}}</option>--}}
                        @else
                            <option value="">==市==</option>
                        @endif
                    </select>
                    <select name="county" id="county" style="width: 130px;">
                        @if($order && $order->city)
                            @foreach($countys as $county)
                                <option value="{{$county->id}}"
                                        @if($order && $order->county == $county->id)
                                        selected
                                        @endif>
                                    {{$county->name}}
                                </option>
                            @endforeach
                        @else
                            <option value="">==县==</option>
                        @endif
                    </select>
                    <input id="addr" name="addr" type="text"
                           class="dfinput" value="{{isset($order)?($order->addr):''}}" placeholder="详细街道地址"/>
                </li>

                <li>
                    <label class="lable">联系方式</label>
                    <input id="tel" name="tel" type="text"
                           class="dfinput" value="{{isset($order)?($order->tel):''}}"/>
                    <i for="tel"></i>
                </li>

                <li>
                    <label class="lable">订单备注</label>
                    <input id="detail" name="detail" type="text"
                           class="dfinput" value="{{isset($order)?($order->detail):''}}"/>
                    <i for="detail"></i>
                </li>

                <li>
                    <label class="lable">物流公司</label>
                    <select id="express_company_id" name="express_company_id">
                        <option value="">--选择发货物流公司--</option>
                        @foreach ($express_companys as $ec)
                            <option value="{{$ec->id}}" {{isset($order) && $order->express_company_id == $ec->id ? 'selected' : ''}}>{{$ec->name}}</option>
                        @endforeach
                    </select>
                    <i for="express_company_id">请选择发货物流公司</i>
                </li>

                <li>
                    <label class="lable">物流单号</label>
                    <input id="express_no" name="express_no" type="text" class="dfinput" placeholder="请填写物流单号"
                           value="{{isset($order)?($order->express_no):''}}"/>
                    <i for="express_no">请填写物流单号</i>
                </li>

                <li><label class="lable">&nbsp;</label>
                    <input type="submit" class="btn" value="确认发货"/>
                </li>
            </ul>
        </form>
    </div>
@endsection

@section('footer')
    <script type="text/javascript">
        $("#admin").validate({
            rules: {
                addr: {required: true},
                tel: {required: true},
//                detail: {required: true},
                express_company_id: {required: true},
                express_no: {required: true}
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("i[for='" + element.attr("id") + "']").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{route('admin.order',['flag'=>1])}}";
                            }, 1000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });

        $("#province").change(function () {
            var province = $("#province").val();
            var url = "{{route('web.address_change')}}";

            if (province == '') {
                $("#city").html("<option value=''>==市==</option>");
                $("#county").html("<option value=''>==县/区==</option>");
            } else {
                $.post(url, {id: province}, function (data) {
                    $("#city").html("<option value=''>==市==</option>");
                    $("#county").html("<option value=''>==县/区==</option>");
                    $("#city").append(data);
                }, "text");
            }
        });
        $("#city").change(function () {
            var id = $(this).val();
            var url = "{{route('web.address_change')}}";
            if (id == '') {
                $("#county").html("<option value=''>==县/区==</option>");
            } else {
                $.post(url, {id: id}, function (data) {
                    $("#county").html("<option value=''>==县/区==</option>");
                    $("#county").append(data);
                }, "text");

            }

        });
    </script>
@endsection
